package com.vii.brillien.services.websocket.applications.purity;

import com.vii.streamline.services.MathServices;
import com.vii.streamline.structures.collections.InnerMap;
import org.glassfish.grizzly.websockets.DefaultWebSocket;
import org.glassfish.grizzly.websockets.ProtocolHandler;
import org.glassfish.grizzly.websockets.WebSocketListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class PureWebSocket extends DefaultWebSocket {

    protected Logger                    logger;
    protected String                    entityName;
    protected Map<String, Object>       properties;

    {
        logger      =   LoggerFactory.getLogger(this.getClass());
        entityName  =   MathServices.newId();
        properties  =   new InnerMap<String, Object>();
    }

    public PureWebSocket(ProtocolHandler protocolHandler, WebSocketListener... listeners) {
        super(protocolHandler, listeners);
    }
    
    public String getEntityName(){
        return entityName;
    }

    public void setEntityName(String entityName) {
        this.entityName = entityName;
    }

    public Map<String, Object> getProperties() {
        return properties;
    }

    public void setProperties(Map<String, Object> properties) {
        this.properties = properties;
    }
    
    public <T> T getProperty(String name){
        return (T)properties.get( name );
    }

    public boolean hasProperty(String name){
        return properties.containsKey( name );
    }

    public void addProperty(String name, Object value){
        properties.put( name, value );
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof PureWebSocket)) return false;

        PureWebSocket that = (PureWebSocket) o;

        if (entityName != null ? !entityName.equals(that.entityName) : that.entityName != null) return false;

        return true;
    }

}
